<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/7/31
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form id="formId" method="post">
        用户名：<input type="text" name="name"/><br/>
        密码：<input type="text" name="password"/><br/>
        验证码：<input type="text" name="code"/>
        <img id="verigyCodeId" src="<%=request.getContextPath()%>/verifyCode" onclick="refresh()"/>
        <br/>
        <input type="button" onclick="submitForm()" value="登录"/>
    </form>

    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=request.getContextPath()%>/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=request.getContextPath()%>/static/mylayer.js" type="text/javascript" charset="utf-8"></script>

    <script>
        function refresh() {
            $('#verigyCodeId').attr('src', '<%=request.getContextPath()%>/verifyCode?' + Math.random());
        }

        function submitForm() {
            // {'name':'lisi', 'password':'123'}
            $.post(
                '<%=request.getContextPath()%>/user?method=login',
                $('#formId').serialize(),
                function(result) {
                    console.log(result);
                    //{msg: '登录成功', code: 0}
                    /*if (result.ok) {

                    }*/
                    if (result.code == 0) {
                        mylayer.okUrl(result.msg, '<%=request.getContextPath()%>');
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
